package com.hy.service;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ConversationHistoryService {

    private final List<String> history = new ArrayList<>();

    public void addQuestion(String question) {
        history.add(question);
    }

    public String getRecentHistory() {
        int startIndex = Math.max(0, history.size() - 4);
        StringBuilder sb = new StringBuilder();
        for (int i = startIndex; i < history.size(); i++) {
            sb.append(history.get(i));
        }
        return sb.toString();
    }
}
